/**
 * 
 */
let mlocation;
let uVue = new Vue({
	el:'#uSpace',
	data:{
		showdiv:[
			{isshow:true},
			{isshow:false},
			{isshow:false},
			{isshow:false},
			{isshow:false},
		],
		userD:{},
		resumeList:[],
		imageUrl:'',
		uimg:null,
		npwd:'',
		opwd:'',
		userDtable:[
			{isM:true,isEnable:false},
			{isM:true,isEnable:false},
			{isM:true,isEnable:false},
			{isM:true,isEnable:false},
			{isM:true,isEnable:false},
			{isM:true,isEnable:false},
		],
		interest:[],
		interestList:[],
		ruleForm:{
			uid:'',
			upwd:'',
			uimg:null,
			ugender:'',
			uinterest:'',
			uemail:'',
			uphone:''
		}
	},
	created(){
		let _this = this;
			axios.post('/usert/interest')
				 .then((response)=>{
					_this.interestList = response.data;
					console.log(response.data);
					
				}).catch(error=>{
					console.log("error:"+error);
				});
		mlocation = window.location.href;
		let uid = mlocation.split('=')[1];
		console.log(mlocation+"--"+uid);
		let data = new FormData();
		data.append("uid",uid);
		axios.post('/usert/userD',data)
				.then(success=>{
					this.userD = success.data;
					this.interest = this.userD.uinterest.split(',');
					this.getresume();
					console.log(success);
				}).catch(error=>{
					console.log("error");
				});
	},
	methods:{
		logout(){
			let logoutBtn = document.getElementById("ulogout");
			logoutBtn.click();
		},
		dmyresume(rfid,path){
			let a = document.createElement('a')
		    a.href ="/hrt/dloadresume?path="+path;
		    a.click();
		},
		getresume(){
			axios.get('/usert/getresume',{
				params:{
					uid:this.userD.uid
				}
			}).then(resp=>{
				this.resumeList = resp.data;
			//	console.log(resp.data);
			}).catch
		},
		submitPwd(){
			let data = new FormData();
			data.append("uid",this.userD.uid);
			data.append("upwd",this.npwd);
			data.append("checkpwd",this.opwd);
			axios.post('/usert/modifyUpwd',data)
				 .then((response)=>{
					this.$message.success("修改成功");
					let timeOut = setTimeout(()=>{
						window.location.href='http://localhost:8082/';
					},3000);
				}).catch(error=>{
					this.$message.error("修改失败，请重试");
				});
		},
		show(index){
			for(let i = 0;i<this.showdiv.length;i++){
				if(i===index){
					this.showdiv[i].isshow = true;
				}
				else{
					this.showdiv[i].isshow = false;
				}
				
			}
			
		},
		uploadUserImg(item){
			//console.log(item);
			this.imageUrl = URL.createObjectURL(item.file);//blobUrl
			this.userDtable[5].isEnable = true;
			console.log(this.imageUrl);
			this.uimg = item.file;
		},
        beforeAvatarUpload(file) {
	        const isJPG = file.type === 'image/jpeg';
	        const isLt2M = file.size / 1024 / 1024 < 2;
	
	        if (!isJPG) {
	          this.$message.error('上传头像图片只能是 JPG 格式!');
	        }
	        if (!isLt2M) {
	          this.$message.error('上传头像图片大小不能超过 2MB!');
	        }
	        return isJPG && isLt2M;
      },
		submit(){
			let data = new FormData();
			data.append("uid",this.userD.uid);
			data.append("ugender",this.userD.ugender);
			data.append("uemail",this.userD.uemail);
			data.append("uphone",this.userD.uphone);
			data.append("uinterest",this.userD.uinterest);
		  //  data.append("uimg",this.);
			if( this.uimg !==null){
				data.append("uimg",this.uimg);
			}
			else{
				data.append('uimg1',this.userD.uimg);
			}
			console.log(this.userD.uimg);
			axios.post('/usert/editUsert',data)
				 .then((response)=>{
					this.$message.success("修改成功");
					for(let i = 0;i<this.userDtable.length;i++)
						this.userDtable[i].isEnable = false;
						let data1 = new FormData();
						data1.append("uid",this.userD.uid);
						axios.post('/usert/userD',data1)
								.then(success=>{
									this.userD = success.data;
									this.interest = this.userD.uinterest.split(',');
									console.log(success);
								}).catch(error=>{
									console.log("error");
								});
				}).catch(error=>{
					this.$message.error("修改失败，请重试");
					console.log("error:"+error);
				});
			
		}
	}
});